<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<script
	src="<%=request.getContextPath()%>/scripts/jstree/jquery.jstree.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/Menu.js"
	type="text/javascript"></script>

<script type="text/javascript">
$().ready(function(){
	initRoleTree();
});
function initRoleTree(){
	$("#roleTree").jstree({//角色树
        "json_data" : {
            "ajax" : {
                "url" : "<%=request.getContextPath()%>/role.do?method=getRoleTree",
				"data" : function(n) {
						}
					},
				'success':function(data){
					console.log(data);
				}
				},
				"ui":{
					 "initially_select" : [ "4" ]//初始化选中项为系统管理员
				},
				"contextmenu":{
					"items":{
						"create":{
							"label":"新建角色",
							"action":function(obj){
								createIframeDialog('角色新增页面','./RoleAdd.jsp',400,280);
							}
						},
						"rename":{
							"label":"编辑角色",
							"action":function(obj){
								createIframeDialog('角色编辑页面','<%=request.getContextPath()%>/role.do?method=updateRole&id='+obj.attr('id'),400,280);
							}
						},
						"remove":{
							"label":"删除角色",
							"action":function(obj){
								createIframeDialog('角色编辑页面','<%=request.getContextPath()%>/role.do?method=deleteRoleById&id='+obj.attr('id'),400,280);
							}
						},
						"ccp":null
					}
				},
		"plugins" : [ "themes",
				"json_data","ui" ]
	}).bind("select_node.jstree", function (event, data) {
		if(data.rslt.obj.attr("id")==''){
			return false;
		}else{
			getRoleInfoByTree(data.rslt.obj.attr("id"));
		}
	});
	$("#roleTree").bind("loaded.jstree", function (e, data) {
		$($('.jstree-leaf').find('a').get(0)).click();//默认选中树的第一个子项
		//$(DOM对象).get(i)返回的是一个DOM对象，不能直接调用click方法，但是在Firefox中不报错，在Chrome中则会出现点击事件不响应的现象
	});
}
	</script>

<table cellspacing="0" cellpadding="6" border="0" width="180"
	class="blockTable">
	<tbody>
		<tr>
			<td class="blockTd" style="padding: 6px;" id="uid_td4">
				<div class="treeItem" id="roleTree" style="width:160px;"></div>
			</td>
		</tr>
	</tbody>
</table>
